package com.study.sxc.service;

import com.study.sxc.Dao.IStaffDao;
import com.study.sxc.Entity.Staff;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class staffService {

    private static final Logger log = LoggerFactory.getLogger(staffService.class);

    @Resource
    IStaffDao staffDao;

    public List<Staff> getStaffs(List<Integer> ids) {
        log.info("查询员工列表，参数：{}", ids);
        List<Staff> staffs = staffDao.getStaffs(ids);
        log.info("DAO层返回数据：{}", staffs);
        if(staffs == null || staffs.isEmpty()) {
            return new ArrayList<>();
        }
        return staffs;
    }

    public int addStaff(Staff staff) {
        log.info("新增员工，参数：{}", staff);
        int result = staffDao.addStaff(staff);
        log.info("新增员工结果：{}", result);
        return result;
    }

    public int updateStaff(Staff staff) {
        log.info("更新员工，参数：{}", staff);
        int result = staffDao.updateStaff(staff);
        log.info("更新员工结果：{}", result);
        return result;
    }

    public int deleteStaff(Integer id) {
        log.info("删除员工，参数：{}", id);
        int result = staffDao.deleteStaff(id);
        log.info("删除员工结果：{}", result);
        return result;
    }

    public Staff getStaffById(Integer id) {
        return staffDao.getStaffById(id);
    }

    /**
     * 查询所有员工
     */
    public List<Staff> getAllStaffs() {
        return staffDao.getAllStaffs();
    }
} 